//
//  main.cpp
//  P1068
//
//  Created by 洋犀利 on 2019/10/11.
//  Copyright © 2019 洋犀利. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;
int n;

struct Student{
    int math;
    int chinese;
    int english;
    int id;
    int all;
    
};

bool cmp(Student a,Student b){
    if(a.all != b.all){
        return a.all>b.all;
    }
    if(a.all == b.all && a.chinese != b.chinese){
        return a.chinese>b.chinese;
    }
    if(a.all == b.all && a.chinese == b.chinese){
        return a.id<b.id;
    }
    return true;
}

int main(int argc, const char * argv[]) {
    Student stus[301] ={};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>stus[i].chinese>>stus[i].math>>stus[i].english;
        stus[i].all =stus[i].chinese+stus[i].math+stus[i].english;
        stus[i].id=i+1;
    }
    sort(stus,stus+n+1,cmp);
    for(int i=0;i<5;i++){
        cout<<stus[i].id<<" "<<stus[i].all<<endl;
    }
    return 0;
}
